package com.nulldev.util.net.experimental.udp2;

import java.util.UUID;

import com.nulldev.util.net.experimental.udp2.util.SerializationUtils;
import com.nulldev.util.string.StringsUtil;

public class Message {
	// The data that was received
    private byte[] data;

    // Network type that was sent
    private NetworkSendType networkSendType;

    // Sequence id of message
    private int sequenceId;

    // connection id
    private UUID connectionID;

    // Sequence number when splitting messages
    private int splitMessageId;

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    public NetworkSendType getNetworkSendType() {
        return networkSendType;
    }

    public void setNetworkSendType(NetworkSendType networkSendType) {
        this.networkSendType = networkSendType;
    }

    public int getSequenceId() {
        return sequenceId;
    }

    public void setSequenceId(int sequenceId) {
        this.sequenceId = sequenceId;
    }

    public UUID getConnectionID() {
        return connectionID;
    }

    public void setConnectionID(UUID connectionID) {
        this.connectionID = connectionID;
    }

    public int getSplitMessageId() {
        return splitMessageId;
    }

    public void setSplitMessageId(int splitMessageId) {
        this.splitMessageId = splitMessageId;
    }
    
    public <T> T read() {
    	return SerializationUtils.getInstance().deserialize(this.data);
    }
    
    @Override
    public String toString() {
    	return "Message[uuid=" + this.connectionID + ",seqID=" +
    				this.sequenceId + ",smID=" + this.splitMessageId + ",data.hash=" + StringsUtil.hash(this.data) + "]";
    }
}
